<template>
	<view class="mainpadding">
		<view class="scbox flexcenter" v-if="!avatar_text" @click="uploadImg">
			<view class="" >
				<view class="flexcenter">
					<u-icon name="plus" color="#B8B8B8" size="58"></u-icon>
				</view>
				<view class="sanshier margin_top textcenter" style="color: #B8B8B8;">添加图片</view>
			</view>
		</view>
		<image :src="avatar_text" v-else class="imgbox" mode="" @click="uploadImg"></image>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit">提交支付信息</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				avatar:"",
				avatar_text:"",
				pay_type:1
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.pay_type = options.pay_type
		},
		methods: {
			uploadImg(value, upImgs, upImgs_text) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.avatar = res.url;
					this.avatar_text = url

				}).catch(err => {});
			},
			submit(){
				if(this.avatar==""){
					httpRequest.toast("请上传支付凭证")
					return false
				}
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.request('/api/ordercl/uploadOrderPayImage', 'GET', {
					id:this.listid,
					pay_image:this.avatar,
					pay_type:this.pay_type
				}).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.scbox {
		width: 100%;
		background: #F6F7F9;
		height: 370rpx;
	}
	.imgbox{
		width: 100%;
		height: 370rpx;
	}
</style>